'use strict';

function DropdownSelect(selector) {
    if ( typeof(selector) == 'string' ) {
        this.$widget = $(selector);
    }
    else {
        this.$widget = selector;
    }
    this.$input = this.$widget.find('input');
    this.$options = this.$widget.find('ul');
    this.$text = this.$input.parent('a').find('span');
}

Object.defineProperty(DropdownSelect.prototype, 'value', {
    get: function() {
        return this.$input.val();
    },
    set: function(value) {
        this.$input.val(value);
        var name = this.$options.find('a[value="' + value + '"]').text();
        this.$text.text(name);
    }
});

Object.defineProperty(DropdownSelect.prototype, 'text', {
    get: function() {
        return this.$text.text();
    }
});
